package h0909;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;

/**
  * @description 每日温度
  * @author 不知名帅哥
  * @date 2024/9/9 18:18
  * @version 1.0
*/
public class EveryDayTemperature {
    public static void main(String[] args) {
        int[] temperatures={73,74,75,79,69,72,76,73};
        int[] ints = dailyTemperatures(temperatures);
        System.out.println(Arrays.toString(ints));
    }
    public static int[] dailyTemperatures(int[] temperatures) {
        LinkedList<int[]> stack=new LinkedList<>();
        int[] ans=new int[temperatures.length];
        stack.addLast(new int[]{temperatures[0],0});
        for (int i = 1; i < temperatures.length; i++) {
            while (!stack.isEmpty()&&temperatures[i]>stack.peekLast()[0]){
                int[] temp = stack.removeLast();
                ans[temp[1]]=i-temp[1];
            }
            stack.addLast(new int[]{temperatures[i],i});
        }
        return ans;
    }
}
